﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Composite_controls
{
    public partial class SearchBox : UserControl
    {
        public SearchBox()
        {
            InitializeComponent();
        }

        [Browsable(false)] //编译器将Xyz这个属性不显示在属性面板了
        public string Xyz
        {
            get;
            set;
        }
        [Category("Appearance")]  //SearchText属性默认是在杂项中 
        //此处是将SearchText从杂项中添加到了属性的外观中

        //设计器是否自动生成代码
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public string SearchText
        {
            get
            {
                return lineEdit.Text;
            }
            set
            {
                lineEdit.Text = value;
            }
        }


        //设计器是否自动生成代码
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
       [Browsable(true)] //编译器将Text这个属性显示在属性面板了
        //重写
        public override string Text
        {
            get
            {
                return lineEdit.Text;
            }
            set
            {
                lineEdit.Text = value;
            }
        }
        //自定义事件
        public event EventHandler SearchEvent;

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            if (SearchEvent != null)
            {
                SearchEvent.Invoke(this, e);
            }
            
            //也可以写成这种方式
            //SearchEvent?.Invoke(this ,e) ;
        }
    }
}
